// This sample program demonstrates how to decode a JSON string.
package main

import (
	"encoding/json"
	"log"
	"fmt"
)

// JSON contains a sample string to unmarshal.
var JSONMapDemo = `{
	"name": "Gopher",
	"title": "programmer",
	"contact": {
		"home": "415.333.3333",
		"cell": "415.555.5555",
		"address": {
			"province":"湖南",
			"city":"衡阳"
		}
	}
}`

/**
*	通过map保存json对象,并访问其中的节点信息
 */
func main() {
	// Unmarshal the JSON string into our map variable.

	// 将json对象映射到map中去
	var c map[string]interface{}
	err := json.Unmarshal([]byte(JSONMapDemo), &c)
	if err != nil {
		log.Println("ERROR:", err)
		return
	}

	fmt.Println("Name:", c["name"])
	fmt.Println("Title:", c["title"])
	fmt.Println("Contact")
	fmt.Println("H:", c["contact"].(map[string]interface{})["home"])
	fmt.Println("C:", c["contact"].(map[string]interface{})["cell"])
	fmt.Println("province:", c["contact"].(map[string]interface{})["address"].(map[string]interface{})["province"])
	fmt.Println("city:", c["contact"].(map[string]interface{})["address"].(map[string]interface{})["city"])
}
